-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport 2.2x: range-based constant-flow base64 #4835
Backport 2.2x: range-based constant-flow base64 #4835
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've verified that the first commits (up to 4ac01d2) are a forward-port of the 2.16 PR, with the obvious conflict resolution, and the manually reviewed the other commits. I'm generally happy with the testing strategy, but have a few reservations about specific points of its implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good apart from 2 nits that I also put on the other backport (since they apply to both I was unsure where to raise them).
ChangeLog.d/base64-ranges.txt
Outdated
Changes | ||
* Improve the performance of base64 constant-flow code. The result is still | ||
slower than the original non-constant-flow implementation, but much faster | ||
than the previous constant-flow implemenation. Fixes #4814. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: "implemenation" -> "implementation"
library/base64.c
Outdated
return (unsigned char) ( 1 ^ difference ); | ||
/* low_mask is: 0 if low <= c, 0x...ff if low > c */ | ||
unsigned low_mask = ( (unsigned) c - low ) >> 8; | ||
/* high_mask is: 0 if c <= high, 0x...ff if high > c */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is wrong: high > c
should be c > high
or high < c
n was used for two different purposes. Give it a different name the second time. This does not seem to change the generated code when compiling with optimization for size or performance. Signed-off-by: Gilles Peskine <[email protected]>
To test c <= high, instead of testing the sign of (high + 1) - c, negate the sign of high - c (as we're doing for c - low). This is a little easier to read and shaves 2 instructions off the arm thumb build with arm-none-eabi-gcc 7.3.1. Signed-off-by: Gilles Peskine <[email protected]>
I had originally thought to support directories with mbedtls_x509_crt_parse_path but it would have complicated the code more than I cared for. Remove a remnant of the original project in the documentation. Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
Add unit tests for mask_of_range(), enc_char() and dec_value(). When constant-flow testing is enabled, verify that these functions are constant-flow. Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
This is part of the definition of the encoding, not a choice of test parameter, so keep it with the test code. Signed-off-by: Gilles Peskine <[email protected]>
digits is also a local variable in host_test.function, leading to compilers complaining about that shadowing the global variable in test_suite_base64.function. Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
3e49b1a
to
1222fed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-approving after rebase - I checked that the only differences are the ones announced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks!
Fix #4814. See #4819.
Compared to the 2.16 version:
mbedtls_base64_decode
itself due to its logic relying on equality tests of string contents against non-digit values (e.g.src[i] == ' '
); I haven't found a way to get rid of those equality tests without a significant cost in both performance and code size.I expect the 3.0 forward-port to be identical except for further build script tweaks and for timing in
load_roots
needing adjustments (or maybe we can do the easy thing and remove it). I'll make it after the 2.2x version has at least one approval.